package com.lsh.multithreading;

/**
 * @author ：LiuShihao
 * @date ：Created in 2020/12/18 4:58 下午
 * @desc ：
 */
public class Sync_01 {
    public static void main(String[] args) {
        new Thread(() ->{
            while (true){
                Printer_02.print1();
            }

        }).start();

        new Thread(() ->{
            while (true){
                Printer_02.print2();
            }

        }).start();
    }

}
class Printer_02 {

    // 非静态的的同步方法的锁对象是什么?
    // 答:是this

    // 静态同步方法的锁对象是什么?
    // 答:是该类的字节码对象
    public static synchronized void print1() {
        System.out.print("1 ");
        System.out.print("2 ");
        System.out.print("3 ");
        System.out.print("4 ");
        System.out.println("");
        // System.out.println("1 2 3 4 ");

    }

    public static void print2() {
        synchronized (Printer_02.class) {

            System.out.print("一 ");
            System.out.print("二 ");
            System.out.print("三 ");
            System.out.print("四 ");
            System.out.println("");
        }
    }
}
